package com.example.server.controller;

import com.example.server.pojo.MyRole;
import com.example.server.pojo.RespBean;
import com.example.server.service.MyRoleService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@Slf4j
@RequestMapping("/api")
public class MyRoleCtl {
    @Autowired
    private MyRoleService myRoleService;

    @ApiOperation(value = "查询角色权限")
    @GetMapping("/roleOfPower/{roleid}")
    public RespBean roleOfPower(@PathVariable("roleid") Long roleid){
        List<MyRole> result = myRoleService.roleOfPower(roleid);
        log.info("-----roleOfPower结果："+result);

        if (result != null){
            return new RespBean(200,"success",result);
        }else {
            return new RespBean(402,"获取员工失败",null);
        }
    }

    @ApiOperation(value = "查询角色权限")
    @GetMapping("/roleOfPower1/{roleid}")
    public RespBean roleOfPower1(@PathVariable("roleid") Long roleid){
        ArrayList<Map<Object, Object>> result = myRoleService.roleOfPower1(roleid);
        log.info("-----roleOfPower1结果："+result);

        if (result != null){
            return new RespBean(200,"success",result);
        }else {
            return new RespBean(402,"查询角色权限失败",null);
        }
    }

    @ApiOperation(value = "查询所有角色")
    @GetMapping("/allRole")
    public RespBean allRole(){
        List<MyRole> result = myRoleService.allRole();
        log.info("-----allRole结果："+result);

        if (result != null){
            return new RespBean(200,"success",result);
        }else {
            return new RespBean(402,"获取角色失败",null);
        }
    }

    @ApiOperation(value = "查询所有角色")
    @DeleteMapping("/delRole/{roleid}")
    public RespBean delRole(@PathVariable("roleid") Long roleid){
        Integer result = myRoleService.delRole(roleid);
        log.info("-----delRole结果："+result);

        if (result != null){
            return new RespBean(200,"success",result);
        }else {
            return new RespBean(402,"获取角色失败",null);
        }
    }
}
